﻿using DAO.DAOUtils;
using DAO.IAuthorizationDAO;
using DTO.Authorization;
using DTO.DTOUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO.AuthorizationDAO
{
    public class UserTypeDAO : IUserTypeDAO
    {

        public bool Insert(DTO.Authorization.UserTypeDTO userType)
        {
            var parameters = GetListParameterNonId(ref userType);
            return SQLUtils.ExcuteNoneQuery("UserTypeInsert", ref parameters);
        }

        public bool DeleteById(string userTypeId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.UserTypeId, userTypeId));
            return SQLUtils.ExcuteNoneQuery("UserTypeDeleteById", ref parameters);
        }

        public bool DeleteByName(string userTypeName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.UserTypeName, userTypeName));
            return SQLUtils.ExcuteNoneQuery("UserTypeDeleteByName", ref parameters);
        }

        public bool UpdateById(DTO.Authorization.UserTypeDTO newUserType)
        {
            var parameters = GetListParameter(ref newUserType);
            return SQLUtils.ExcuteNoneQuery("UserTypeUpdateById", ref parameters);
        }

        public List<Parameter> GetListParameter(ref UserTypeDTO userType)
        {
            return Parameter.CreateList(
                    new Parameter(DTOConstant.UserTypeId, userType.Id),
                    new Parameter(DTOConstant.UserTypeName, userType.UserTypeName),
                    new Parameter(DTOConstant.UserTypeDes, userType.UserTypeDes)
                );
        }

        public List<Parameter> GetListParameterNonId(ref UserTypeDTO userType)
        {
            return Parameter.CreateList(
                    new Parameter(DTOConstant.UserTypeName, userType.UserTypeName),
                    new Parameter(DTOConstant.UserTypeDes, userType.UserTypeDes)
                );
        }

        public System.Data.DataTable GetAll()
        {
            var parameters = Parameter.CreateList();
            return SQLUtils.ExcuteQuery("UserTypeGetAll", ref parameters);
        }

        public System.Data.DataTable GetByName(string userTypeName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.UserTypeName, userTypeName));
            return SQLUtils.ExcuteQuery("UserTypeGetByName", ref parameters);
        }

        public System.Data.DataTable GetById(string userTypeId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.UserTypeId, userTypeId));
            return SQLUtils.ExcuteQuery("UserTypeGetById", ref parameters);
        }
    }
}
